package com.zte.market.service.impl;

import com.zte.market.mapper.CityMapper;
import com.zte.market.mapper.ProvinceMapper;
import com.zte.market.pojo.City;
import com.zte.market.pojo.Province;
import com.zte.market.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CityServiceImpl implements CityService {


    @Autowired
    private CityMapper cityMapper;

    @Autowired
    private ProvinceMapper provinceMapper;

    @Override
    public List<City> queryCitys(Integer pId) {
        return cityMapper.queryCitys(pId);
    }

    /**
     * 根据 id 查询城市
     * @param id 参数
     * @return
     */
    @Override
    public City queryById(Integer id) {
        City city = cityMapper.queryById(id);
        //向城市信息中添加对应省份信息
        Province province = provinceMapper.queryById(city.getPId());
        city.setProvince(province);
        return city;
    }
}
